﻿namespace Hidistro.UI.Web.API
{
    using Hidistro.ControlPanel.Sales;
    using Hidistro.Core;
    using Hidistro.Entities;
    using Hidistro.Entities.Commodities;
    using Hidistro.Entities.Orders;
    using Hidistro.Entities.Promotions;
    using Hidistro.Entities.Sales;
    using Hidistro.Membership.Context;
    using Hidistro.Membership.Core;
    using Hidistro.Messages;
    using Hidistro.SaleSystem.Member;
    using Hidistro.UI.Web;
    using Hishop.Plugins;
    using Newtonsoft.Json;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.IO;
    using System.Net;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Web;
    using System.Web.Services;
    using System.Xml;

    [WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1), WebService(Namespace="http://tempuri.org/")]
    public class OrdersHandler : IHttpHandler
    {
        private string erromsg = "";
        private string fomat = "";
        private string key = "";
        private string localcode = "";
        private string ModelId = "";
        private int pagesize = 10;
        private SortedDictionary<string, string> tmpParas = new SortedDictionary<string, string>();

        public StringBuilder GetOrderDetails(string format, string orderitemfomat, OrderInfo order)
        {
            StringBuilder builder = new StringBuilder();
            string str = string.Empty;
            if (order == null)
            {
                return builder;
            }
            string str2 = "false";
            StringBuilder builder2 = new StringBuilder();
            long num = 0L;
            foreach (LineItemInfo info in order.LineItems.Values)
            {
                str2 = "true";
                builder2.AppendFormat(orderitemfomat, new object[] { "0", order.OrderId, info.ProductId.ToString(), info.ItemDescription, info.SKU, Globals.HtmlEncode(info.SKUContent), info.Quantity.ToString(), info.ItemListPrice.ToString("F0"), info.ItemAdjustedPrice.ToString("F0"), info.ThumbnailsUrl });
                num += info.Quantity;
            }
            if ((this.fomat == "json") && (builder2.Length > 0))
            {
                builder2 = builder2.Remove(builder2.ToString().LastIndexOf(','), 1);
            }
            Dictionary<string, string> shippingRegion = MessageInfo.GetShippingRegion(order.ShippingRegion);
            string modeName = order.ModeName;
            if (!string.IsNullOrEmpty(order.RealModeName))
            {
                modeName = order.RealModeName;
            }
            if (string.IsNullOrEmpty(str))
            {
                str = order.ModeName;
            }
            string str4 = "";
            string str5 = "";
            if (order.PayDate.Year != 1)
            {
                str4 = order.PayDate.ToString("yyyy-MM-dd");
            }
            if (order.ShippingDate.Year != 1)
            {
                str5 = order.ShippingDate.ToString("yyyy-MM-dd");
            }
            builder.AppendFormat(format, new object[] { 
                order.OrderId, "0", order.Username, order.EmailAddress, order.ShipTo, shippingRegion["Province"], shippingRegion["City"].ToString(), shippingRegion["District"], order.Address, order.ZipCode, order.CellPhone, order.TelPhone, Globals.HtmlEncode(order.Remark), order.ManagerMark, order.ManagerRemark, num.ToString(), 
                order.GetTotal().ToString("F0"), order.GetTotal().ToString("F0"), order.Gateway, order.PaymentTypeId.ToString(), order.PaymentType, order.AdjustedFreight.ToString("F0"), order.ReducedPromotionAmount.ToString("F0"), order.AdjustedDiscount.ToString("F0"), str4, str5, ((int) order.RefundStatus).ToString(), order.RefundAmount.ToString("F0"), order.RefundRemark, ((int) order.OrderStatus).ToString(), modeName, str2, 
                builder2
             });
            if (!string.IsNullOrEmpty(order.ShippingRegion))
            {
                str = order.ShippingRegion;
            }
            if (!string.IsNullOrEmpty(order.Address))
            {
                str = str + order.Address;
            }
            if (!string.IsNullOrEmpty(order.ShipTo))
            {
                str = str + "   " + order.ShipTo;
            }
            if (!string.IsNullOrEmpty(order.ZipCode))
            {
                str = str + "   " + order.ZipCode;
            }
            if (!string.IsNullOrEmpty(order.TelPhone))
            {
                str = str + "   " + order.TelPhone;
            }
            if (!string.IsNullOrEmpty(order.CellPhone))
            {
                str = str + "   " + order.CellPhone;
            }
            string str6 = "<ShipAddress>{0}</ShipAddress><ShipOrderNumber>{1}</ShipOrderNumber><ExpressCompanyName>{2}</ExpressCompanyName>";
            if (this.fomat == "json")
            {
                str6 = "\"ShipAddress\":\"{0}\",\"ShipOrderNumber\":\"{1}\",\"ExpressCompanyName\":\"{2}\"";
            }
            str6 = string.Format(str6, str, order.ShipOrderNumber, order.ExpressCompanyName);
            if (this.fomat == "json")
            {
                builder = builder.Replace(",\"ModeName", "," + str6 + ",\"ModeName");
                return builder.Remove(builder.ToString().LastIndexOf(','), 1);
            }
            return builder.Replace("</Status>", "</Status>" + str6);
        }

        public StringBuilder GetOrderList(OrderQuery query, string format, string orderitemfomat, out int totalrecords)
        {
            int records = 0;
            Globals.EntityCoding(query, true);
            DataSet tradeOrders = OrderHelper.GetTradeOrders(query, out records);
            StringBuilder builder = new StringBuilder();
            string str = "";
            foreach (DataRow row in tradeOrders.Tables[0].Rows)
            {
                string str2 = "false";
                StringBuilder builder2 = new StringBuilder();
                foreach (DataRow row2 in row.GetChildRows("OrderRelation"))
                {
                    string str3 = Globals.HtmlEncode(row2["SKUContent"].ToString());
                    str2 = "true";
                    str = row2["ThumbnailsUrl"].ToString();
                    builder2.AppendFormat(orderitemfomat, new object[] { row2["Tid"].ToString(), row2["OrderId"].ToString(), row2["ProductId"].ToString(), row2["ItemDescription"].ToString(), row2["SKU"].ToString(), str3, row2["Quantity"].ToString(), decimal.Parse(row2["ItemListPrice"].ToString()).ToString("F0"), decimal.Parse(row2["ItemAdjustedPrice"].ToString()).ToString("F0"), str });
                }
                if ((this.fomat == "json") && (builder2.ToString().Length > 0))
                {
                    builder2 = builder2.Remove(builder2.ToString().LastIndexOf(','), 1);
                }
                Dictionary<string, string> shippingRegion = MessageInfo.GetShippingRegion(row["ShippingRegion"].ToString());
                builder.AppendFormat(format, new object[] { 
                    row["OrderId"].ToString(), row["SellerUid"].ToString(), row["Username"].ToString(), row["EmailAddress"].ToString(), row["ShipTo"].ToString(), shippingRegion["Province"], shippingRegion["City"].ToString(), shippingRegion["District"], row["Address"].ToString(), row["ZipCode"].ToString(), row["CellPhone"].ToString(), row["TelPhone"].ToString(), Globals.HtmlEncode(row["Remark"].ToString()), row["ManagerMark"].ToString(), row["ManagerRemark"].ToString(), row["Nums"].ToString(), 
                    decimal.Parse(row["OrderTotal"].ToString()).ToString("F0"), decimal.Parse(row["OrderTotal"].ToString()).ToString("F0"), row["Gateway"].ToString(), row["PaymentTypeId"].ToString(), row["PaymentType"].ToString(), decimal.Parse(row["AdjustedFreight"].ToString()).ToString("F0"), "0.00", decimal.Parse(row["AdjustedDiscount"].ToString()).ToString("F0"), row["PayDate"].ToString(), row["ShippingDate"].ToString(), row["ReFundStatus"].ToString(), row["RefundAmount"].ToString(), row["RefundRemark"].ToString(), row["OrderStatus"].ToString(), row["ModeName"].ToString(), str2, 
                    builder2
                 });
            }
            if ((this.fomat == "json") && (builder.Length > 0))
            {
                builder = builder.Remove(builder.ToString().LastIndexOf(','), 1);
            }
            totalrecords = records;
            return builder;
        }

        public void ProcessRequest(HttpContext context)
        {
            string format = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><trade_get_response>{0}</trade_get_response>";
            string str2 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
            this.fomat = context.Request.Form["format"];
            SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);
            string str3 = "<trade><Oid>{0}</Oid><SellerUid>{1}</SellerUid><BuyerNick>{2}</BuyerNick><BuyerEmail>{3}</BuyerEmail><ReceiverName>{4}</ReceiverName><ReceiverState>{5}</ReceiverState><ReceiverCity>{6}</ReceiverCity><ReceiverDistrict>{7}</ReceiverDistrict><ReceiverAddress>{8}</ReceiverAddress><ReceiverZip>{9}</ReceiverZip><ReceiverMobile>{10}</ReceiverMobile><ReceiverPhone>{11}</ReceiverPhone><BuyerMemo>{12}</BuyerMemo><OrderMark>{13}</OrderMark><SellerMemo>{14}</SellerMemo><Nums>{15}</Nums><Price>{16}</Price><Payment>{17}</Payment><PaymentType>{18}</PaymentType><PaymentTypeId>{19}</PaymentTypeId><PaymentName>{20}</PaymentName><PostFee>{21}</PostFee><DiscountFee>{22}</DiscountFee><AdjustFee>{23}</AdjustFee><PaymentTs>{24}</PaymentTs><SentTs>{25}</SentTs><RefundStatus>{26}</RefundStatus><RefundAmount>{27}</RefundAmount><RefundRemark>{28}</RefundRemark><Status>{29}</Status><ModeName>{30}</ModeName><orders list=\"{31}\">{32}</orders></trade>";
            string str4 = "{{\"Oid\": \"{0}\",\"SellerUid\": \"{1}\",\"BuyerNick\": \"{2}\",\"BuyerEmail\": \"{3}\",\"ReceiverName\": \"{4}\",\"ReceiverState\": \"{5}\",\"ReceiverCity\": \"{6}\",\"ReceiverDistrict\":\"{7}\",\"ReceiverAddress\":\"{8}\",\"ReceiverZip\": \"{9}\",\"ReceiverMobile\": \"{10}\",\"ReceiverPhone\":\"{11}\",\"BuyerMemo\": \"{12}\",\"OrderMark\":\"{13}\",\"SellerMemo\":\"{14}\",\"Nums\":\"{15}\",\"Price\": \"{16}\",\"Payment\":\"{17}\",\"PaymentType\": \"{18}\",\"PaymentTypeId\":\"{19}\",\"PaymentName\":\"{20}\",\"PostFee\": \"{21}\",\"DiscountFee\": \"{22}\",\"AdjustFee\": \"{23}\",\"PaymentTs\": \"{24}\",\"SentTs\":\"{25}\",\"RefundStatus\":\"{26}\",\"RefundAmount\":\"{27}\",\"RefundRemark\":\"{28}\",\"Status\": \"{29}\",\"ModeName\": \"{30}\",\"orders\":{{\"list\":\"{31}\",\"order\": [{32}]}}}},";
            string orderitemfomat = "<order><Tid>{0}</Tid><Oid>{1}</Oid><GoodsIid>{2}</GoodsIid><Title>{3}</Title><OuterId>{4}</OuterId><SKUContent>{5}</SKUContent><Nums>{6}</Nums><Price>{7}</Price><Payment>{8}</Payment><ThumUrl>{9}</ThumUrl></order>";
            string str6 = "{{\"Tid\": \"{0}\",\"Oid\": \"{1}\",\"GoodsIid\": \"{2}\",\"Title\": \"{3}\",\"OuterId\": \"{4}\",\"SKUContent\": \"{5}\",\"Nums\": \"{6}\",\"Price\": \"{7}\",\"Payment\":\"{8}\",\"ThumUrl\":\"{9}\"}},";
            StringBuilder builder = new StringBuilder();
            this.ModelId = context.Request.QueryString["action"].ToString();
            if (this.ModelId.Equals("paymoney"))
            {
                this.key = context.Request.QueryString["sign"];
            }
            else
            {
                this.key = context.Request.Form["sign"];
            }
            this.localcode = masterSettings.CheckCode;
            new Dictionary<string, string>();
            XmlDocument node = new XmlDocument();
            try
            {
                string str12;
                string str14;
                string str17;
                if (string.IsNullOrEmpty(this.ModelId))
                {
                    goto Label_0974;
                }
                string modelId = this.ModelId;
                if (modelId == null)
                {
                    goto Label_0960;
                }
                if (!(modelId == "tradelist"))
                {
                    if (modelId == "tradedetails")
                    {
                        goto Label_03F7;
                    }
                    if (modelId == "send")
                    {
                        goto Label_0572;
                    }
                    if (modelId == "mark")
                    {
                        goto Label_076D;
                    }
                    goto Label_0960;
                }
                OrderQuery query = new OrderQuery {
                    PageSize = 100
                };
                int totalrecords = 0;
                string str7 = context.Request.Form["status"].Trim();
                string str8 = context.Request.Form["buyernick"].Trim();
                string str9 = context.Request.Form["pageindex"].Trim();
                string str10 = context.Request.Form["starttime"].Trim();
                string str11 = context.Request.Form["endtime"].Trim();
                if ((!string.IsNullOrEmpty(str7) && (Convert.ToInt32(str7) >= 0)) && (str7 != "6"))
                {
                    query.Status = (OrderStatus) System.Enum.Parse(typeof(OrderStatus), str7, true);
                }
                else if (str7 == "6")
                {
                    query.Status = OrderStatus.All;
                    query.RefundState = (RefundStatus) System.Enum.Parse(typeof(RefundStatus), str7, true);
                }
                else
                {
                    this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Empty_Error, "status");
                }
                if (!string.IsNullOrEmpty(str9) && (Convert.ToInt32(str9) > 0))
                {
                    query.PageIndex = Convert.ToInt32(str9);
                }
                else
                {
                    this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Empty_Error, "pageindex");
                }
                if (string.IsNullOrEmpty(this.erromsg))
                {
                    this.tmpParas.Add("status", str7);
                    this.tmpParas.Add("buyernick", str8);
                    this.tmpParas.Add("pageindex", str9);
                    this.tmpParas.Add("starttime", str10);
                    this.tmpParas.Add("endtime", str11);
                    this.tmpParas.Add("format", this.fomat);
                    if (APIHelper.CheckSign(this.tmpParas, this.localcode, this.key))
                    {
                        if (!string.IsNullOrEmpty(str8))
                        {
                            query.UserName = str8;
                        }
                        if (!string.IsNullOrEmpty(str10))
                        {
                            query.StartDate = new DateTime?(Convert.ToDateTime(str10));
                        }
                        if (!string.IsNullOrEmpty(str11))
                        {
                            query.EndDate = new DateTime?(Convert.ToDateTime(str11));
                        }
                        builder.Append(this.GetOrderList(query, str3, orderitemfomat, out totalrecords).ToString());
                        builder.Append("<totalrecord>" + totalrecords + "</totalrecord>");
                        format = string.Format(format, builder.ToString());
                    }
                    else
                    {
                        this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Signature_Error, "sign");
                    }
                }
                else
                {
                    this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Empty_Error, "paramter");
                }
                goto Label_09A3;
            Label_03F7:
                str12 = "";
                if (!string.IsNullOrEmpty(context.Request.Form["tid"].Trim()))
                {
                    str12 = context.Request.Form["tid"].Trim();
                    this.tmpParas = new SortedDictionary<string, string>();
                    this.tmpParas.Add("tid", context.Request.Form["tid"]);
                    this.tmpParas.Add("format", this.fomat);
                    if (APIHelper.CheckSign(this.tmpParas, this.localcode, this.key))
                    {
                        string str13 = context.Request.Form["tid"].Replace("\r\n", "\n");
                        if (!string.IsNullOrEmpty(str13))
                        {
                            str12 = str13;
                            OrderInfo orderInfo = TradeHelper.GetOrderInfo(str12);
                            if (this.fomat == "json")
                            {
                                format = string.Format("{{\"trade_get_response\":{{\"trade\":{0}}}}}", this.GetOrderDetails(str4, str6, orderInfo));
                            }
                            else
                            {
                                format = string.Format(format, builder.Append(this.GetOrderDetails(str3, orderitemfomat, orderInfo).ToString()));
                            }
                        }
                        else
                        {
                            this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Format_Eroor, "tid");
                        }
                    }
                    else
                    {
                        this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Signature_Error, "signature");
                    }
                }
                else
                {
                    this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Empty_Error, "tid");
                }
                goto Label_09A3;
            Label_0572:
                str14 = context.Request.Form["tid"].Trim();
                string str15 = context.Request.Form["out_sid"].Trim();
                string str16 = context.Request.Form["company_code"].Trim();
                if ((!string.IsNullOrEmpty(str14) && !string.IsNullOrEmpty(str16)) && !string.IsNullOrEmpty(str15))
                {
                    this.tmpParas.Add("tid", str14);
                    this.tmpParas.Add("out_sid", str15);
                    this.tmpParas.Add("company_code", str16);
                    this.tmpParas.Add("format", this.fomat);
                    if (APIHelper.CheckSign(this.tmpParas, this.localcode, this.key))
                    {
                        ExpressCompanyInfo express = ExpressHelper.FindNodeByCode(str16);
                        if (!string.IsNullOrEmpty(express.Name))
                        {
                            ShippingModeInfo shippingModeByCompany = SalesHelper.GetShippingModeByCompany(express.Name);
                            OrderInfo order = OrderHelper.GetOrderInfo(str14);
                            if (order != null)
                            {
                                ApiErrorCode messageenum = this.SendOrders(order, shippingModeByCompany, str15, express);
                                if (messageenum == ApiErrorCode.Success)
                                {
                                    order = OrderHelper.GetOrderInfo(str14);
                                    if (this.fomat == "json")
                                    {
                                        format = string.Format("{{\"trade_get_response\":{{\"trade\":{0}}}}}", this.GetOrderDetails(str4, str6, order));
                                    }
                                    else
                                    {
                                        format = string.Format(format, builder.Append(this.GetOrderDetails(str3, orderitemfomat, order).ToString()));
                                    }
                                }
                                else
                                {
                                    this.erromsg = MessageInfo.ShowMessageInfo(messageenum, "It");
                                }
                            }
                            else
                            {
                                this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.NoExists_Error, "tid");
                            }
                        }
                        else
                        {
                            this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.NoExists_Error, "company_code");
                        }
                    }
                    else
                    {
                        this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Signature_Error, "sign");
                    }
                }
                else
                {
                    this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Empty_Error, "paramters");
                }
                goto Label_09A3;
            Label_076D:
                str17 = context.Request.Form["order_mark"].Trim();
                string str18 = context.Request.Form["seller_memo"].Trim();
                if ((!string.IsNullOrEmpty(context.Request.Form["tid"].Trim()) && !string.IsNullOrEmpty(str17)) && !string.IsNullOrEmpty(str18))
                {
                    if ((Convert.ToInt32(str17) > 0) && (Convert.ToInt32(str17) < 7))
                    {
                        str12 = context.Request.Form["tid"].Trim();
                        this.tmpParas.Add("tid", str12);
                        this.tmpParas.Add("order_mark", str17);
                        this.tmpParas.Add("seller_memo", str18);
                        this.tmpParas.Add("format", this.fomat);
                        if (APIHelper.CheckSign(this.tmpParas, this.localcode, this.key))
                        {
                            OrderInfo info5 = OrderHelper.GetOrderInfo(str12);
                            info5.ManagerMark = new OrderMark?((OrderMark) System.Enum.Parse(typeof(OrderMark), str17, true));
                            info5.ManagerRemark = Globals.HtmlEncode(str18);
                            if (OrderHelper.SaveRemark(info5))
                            {
                                if (this.fomat == "json")
                                {
                                    format = string.Format("{{\"trade_get_response\":{{\"trade\":{0}}}}}", this.GetOrderDetails(str4, str6, info5));
                                }
                                else
                                {
                                    format = string.Format(format, builder.Append(this.GetOrderDetails(str3, orderitemfomat, info5).ToString()));
                                }
                            }
                            else
                            {
                                this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Paramter_Error, "save is failure ");
                            }
                        }
                        else
                        {
                            this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Signature_Error, "sign");
                        }
                    }
                    else
                    {
                        this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Format_Eroor, "order_mark");
                    }
                }
                else
                {
                    this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Empty_Error, "tid or order_mark or seller_memo");
                }
                goto Label_09A3;
            Label_0960:
                this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Paramter_Error, "paramters");
                goto Label_09A3;
            Label_0974:
                this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Paramter_Error, "sign");
            }
            catch (Exception exception)
            {
                this.erromsg = MessageInfo.ShowMessageInfo(ApiErrorCode.Unknown_Error, exception.Message);
            }
        Label_09A3:
            if (!string.IsNullOrEmpty(this.erromsg))
            {
                format = str2 + this.erromsg;
                if (this.fomat == "json")
                {
                    format = format.Replace("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>", "");
                    node.Load(new MemoryStream(Encoding.GetEncoding("UTF-8").GetBytes(format)));
                    format = JsonConvert.SerializeXmlNode(node);
                }
            }
            context.Response.ContentType = "text/xml";
            if (this.fomat == "json")
            {
                context.Response.ContentType = "text/json";
            }
            context.Response.Write(format);
        }

        public ApiErrorCode SendOrders(OrderInfo order, ShippingModeInfo shippingmode, string out_id, ExpressCompanyInfo express)
        {
            if ((order.GroupBuyId > 0) && (order.GroupBuyStatus != GroupBuyStatus.Success))
            {
                return ApiErrorCode.Group_Error;
            }
            if (!order.CheckAction(OrderActions.SELLER_SEND_GOODS))
            {
                return ApiErrorCode.NoPay_Error;
            }
            if (shippingmode.ModeId <= 0)
            {
                return ApiErrorCode.NoShippingMode;
            }
            if (string.IsNullOrEmpty(out_id) || (out_id.Length > 20))
            {
                return ApiErrorCode.ShipingOrderNumber_Error;
            }
            order.RealShippingModeId = shippingmode.ModeId;
            order.RealModeName = shippingmode.Name;
            order.ExpressCompanyName = express.Name;
            order.ExpressCompanyAbb = express.Kuaidi100Code;
            order.ShipOrderNumber = out_id;
            if (!OrderHelper.SendGoods(order))
            {
                return ApiErrorCode.Unknown_Error;
            }
            if (!string.IsNullOrEmpty(order.GatewayOrderId))
            {
                PaymentModeInfo paymentMode = SalesHelper.GetPaymentMode(order.PaymentTypeId);
                if (paymentMode != null)
                {
                    PaymentRequest.CreateInstance(paymentMode.Gateway, HiCryptographer.Decrypt(paymentMode.Settings), order.OrderId, order.GetTotal(), "订单发货", "订单号-" + order.OrderId, order.EmailAddress, order.OrderDate, Globals.FullPath(Globals.GetSiteUrls().Home), Globals.FullPath(Globals.GetSiteUrls().UrlData.FormatUrl("PaymentReturn_url", new object[] { paymentMode.Gateway })), Globals.FullPath(Globals.GetSiteUrls().UrlData.FormatUrl("PaymentNotify_url", new object[] { paymentMode.Gateway })), "").SendGoods(order.GatewayOrderId, order.RealModeName, order.ShipOrderNumber, "EXPRESS");
                }
            }
            if (!string.IsNullOrEmpty(order.TaobaoOrderId))
            {
                try
                {
                    WebRequest.Create(string.Format("http://order2.kuaidiangtong.com/UpdateShipping.ashx?tid={0}&companycode={1}&outsid={2}", order.TaobaoOrderId, express.TaobaoCode, order.ShipOrderNumber)).GetResponse();
                }
                catch
                {
                }
            }
            int userId = order.UserId;
            if (userId == 0x44c)
            {
                userId = 0;
            }
            IUser user = Users.GetUser(userId);
            Messenger.OrderShipping(order, user);
            order.OnDeliver();
            return ApiErrorCode.Success;
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

